﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Common;
using DataAccess;

public partial class Manager_ManagerQuestion : System.Web.UI.Page
{
    DataTable table;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Message"] != null)
        {
            lblmes.Text = Session["Message"].ToString();
            Session.Remove("Message");
        }
        else
            lblmes.Text = "";

        LoadQuestion();
    }

    protected void LoadQuestion()
    {
        DbCommand cmd = GenericData.CreateCommand();
        cmd.CommandText = "SELECT Question.ID, Question.Content, Question.Mark, Question.Type, Question.CategoryID, Category.CategoryName , case when Question.Type = 1 then 'Multiple' when Question.Type = 0 then 'Single' End 'TypeQuestion' FROM Question LEFT JOIN Category ON Question.CategoryID = Category.ID ";
        table = GenericData.ExecuteReader(cmd);
        grvQuestion.DataSource = table;
        grvQuestion.DataBind();
    }
 

    protected void grvQuestion_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grvQuestion.PageIndex = e.NewPageIndex;
        LoadQuestion();
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        string QuestionContent = txtkeySearch.Text;
        grvQuestion.DataSource = QuestionDAL.SearchQuestion(QuestionContent);
        grvQuestion.DataBind();
    }
}